package org.kordakus.shoot.gui.action;

import java.awt.event.ActionEvent;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import javax.swing.AbstractAction;
import javax.swing.Icon;

import org.kordakus.shoot.ShootController;
import org.kordakus.shoot.gui.ShootFrame;

public abstract class ShootApplicationAsyncAction extends AbstractAction implements Runnable
{

	private static final long		serialVersionUID	= 5097314651086208194L;

	private static final Executor	_executor			= Executors.newSingleThreadScheduledExecutor();

	private final ShootFrame		_frame;

	private final ShootController	_controller;

	public ShootApplicationAsyncAction(final ShootFrame frame, final ShootController controller, String name, Icon icon)
	{
		super(name, icon);
		this._frame = frame;
		this._controller = controller;
	}

	public final ShootFrame getFrame()
	{
		return _frame;

	}

	public final ShootController getController()
	{
		return _controller;
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		_executor.execute(this);
	}

	@Override
	public void run()
	{
		doAction();
	}

	protected abstract void doAction();

	public static Executor getExecutorService()
	{
		return _executor;
	}

}
